@echo off

setlocal 
%~d0
cd "%~dp0"

set APPCMD="%systemroot%\system32\inetsrv\APPCMD"
set FWKPATH="C:\Windows\Microsoft.NET\Framework\v4.0.30319"
if exist "C:\WINDOWS\Microsoft.NET\Framework64\" set FWKPATH="C:\Windows\Microsoft.NET\Framework64\v4.0.30319"

call updatePSExecutionPolicy.bat

echo.
echo ========= Installing Certificates ========= 

echo Installing CAPICOM...

msiexec /qn /i "%~dp0capicom_dc_sdk.msi"

echo Installing certificate...

IF EXIST "%PROGRAMFILES%\Microsoft CAPICOM 2.1.0.2 SDK" (
    SET capicompath="%PROGRAMFILES%\Microsoft CAPICOM 2.1.0.2 SDK\Samples\vbs\cstore.vbs"
    SET cscript=%windir%\system32\cscript.exe
    %windir%\system32\regsvr32.exe /s "C:\Program Files\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll"
)

IF EXIST "%PROGRAMFILES(x86)%\Microsoft CAPICOM 2.1.0.2 SDK" (
    SET capicompath="%PROGRAMFILES(x86)%\Microsoft CAPICOM 2.1.0.2 SDK\Samples\vbs\cstore.vbs"
    SET cscript=%windir%\syswow64\cscript.exe
    ECHO Setting up CAPICOM for 64 bits environment...
    copy /y "%PROGRAMFILES(x86)%\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll" %windir%\syswow64
    %windir%\syswow64\regsvr32.exe /s %windir%\syswow64\capicom.dll
)

%cscript% /nologo %capicompath% import -l LM "%~dp0mobiletrack.ribeiro.com.ar.pfx" "Passw0rd!"

"%~dp0winhttpcertcfg.exe" -g -c LOCAL_MACHINE\My -s mobiletrack.ribeiro.com.ar -a "IIS_IUSRS"
"%~dp0winhttpcertcfg.exe" -g -c LOCAL_MACHINE\My -s mobiletrack.ribeiro.com.ar -a "NETWORK SERVICE"

echo.
echo ========= Binding SSL Cert to IIS =========
netsh http add sslcert ipport=0.0.0.0:443 certhash=‎a4600a1c466986a358b42e3c5187985f8674049c appid={0C5827DC-AA00-49A6-B26D-D7768EC3F512}
echo SSL certificates bound

echo.
PAUSE